/*
 *Copyright (c) 2008, Scendix Software, Inc.
 * 
 */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Data;
using Microsoft.Win32;

/// <summary>
/// Connects to Database and makes calls
/// </summary>
namespace mceTapiRexv2.Utils
{
    public class connectDB
    {
        public OleDbConnection con;
        private String strConnection;
        public connectDB()
        {
            RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Scendix\\TapiRex");
            String path = key.GetValue("InstallDir").ToString();
            //String path = "D:\\Projects\\TapiRex\\";
            if (path != null)
            {
                strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + path + "data.mdb";
                Connect();
           }
        }
        protected void Connect()
        {
            OleDbConnection conn = null;

            //create the connection from the connection string
            conn = new OleDbConnection(strConnection);

            conn.Open();


            con =  conn;
        }

        public DataSet SelectQuery (String query)
        {
            Connect();
            DataSet dataSet = new DataSet();
            OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
            OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(dataAdapter);
            dataAdapter.SelectCommand = new OleDbCommand(query, con);
            dataAdapter.Fill(dataSet);
            con.Close();
            con.Dispose();
            return dataSet;
        }
        public void Modify (String modify)
        {
            con.Open();
            OleDbCommand command = new OleDbCommand(modify, con);
            command.ExecuteNonQuery();
            con.Close();
            con.Dispose();


        }
    }
}